package sadi.client;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.Border;

import sadi.util.BJConstants;
import sadi.util.CardsCollection;



public class GUI extends JFrame implements BJConstants 
{

	private int clientCardCounter, dealerCardCounter, clientDeckCounter;
	private String userName;
	private JLabel gameRankLabel, trialRankLabel, currentStatusLabel, statusesLabel;
	private JLabel dealerLabel, dealerCardScore;
	private JLabel dealerCardLabel[];
	private JLabel deck1Label, deck1CardScore, deck2Label, deck2CardScore;
	private JLabel clientCardLabel[][];
	private JTable gameRankTable, trialRankTable;
	
	private JScrollPane gameRankScrollPane, trialRankScrollPane;
	private JButton hitButton, standButton, splitButton;

	//Vectors are used to stored the data inside JTable
	//which used to display the game and trial rank
	private Vector<String> columnNames, playerNames; 
	private Vector<Vector> rowData;
	
	private GridBagLayout layout;
	private GridBagConstraints constraints;
	
	private JPanel gameRankPanel, trialRankPanel, currentStatusPanel, dealerPanel, dealerCardPanel, clientPanel, 
					deck1Panel, deck2Panel, deck1CardPanel, deck2CardPanel, buttonPanel, clientCard, dealerInfoPanel, 
					deck1InfoPanel, deck2InfoPanel ;

	private CardsCollection cardsCollection;
	
	private BJClient client;
	
	public GUI()
	{

		//a JOptionPane to ask for username
		userName = JOptionPane.showInputDialog("Please enter your user name:");
		
		//will reject the username if user inputs "dealer"
		while((userName.compareTo(DEALER_USERNAME) == 0))
		{
			JOptionPane.showMessageDialog(this, "Username is reserved. Please choose another user name.", "Error", JOptionPane.WARNING_MESSAGE);
			userName = JOptionPane.showInputDialog("Please enter your user name:");
		}

		setTitle("BlackJack (Username: " + userName + ")");
		
		//creating the default column name vector
		columnNames = new Vector<String>();
		columnNames.addElement("Names");
		columnNames.addElement("Score");
	
		//setting counter
		clientCardCounter = 0;	//counter for client card in one deck
		dealerCardCounter = 1;	//counter for dealer card
		clientDeckCounter = 0;	//to signal which deck is now
		
		dealerCardLabel = new JLabel[5];	//will be storing all the dealer cards' JLabel
		clientCardLabel = new JLabel[MAX_HANDS][MAX_CARDS]; 	//will be storing all the client cards' JLabel
		playerNames = new Vector<String>();
		
		rowData = new Vector<Vector>();
		rowData.addElement(playerNames);
		
		gameRankTable = new JTable(rowData, columnNames){
			public boolean isCellEditable(int rowIndex, int colIndex) {
		        return false;   //Disallow the editing of any cell
		      }
		};
		

		gameRankScrollPane = new JScrollPane(gameRankTable); // add scrollpane
		gameRankScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		
		
		trialRankTable = new JTable(rowData, columnNames){
			public boolean isCellEditable(int rowIndex, int colIndex) {
		        return false;   //Disallow the editing of any cell
		      }
		};
		
		trialRankScrollPane = new JScrollPane(trialRankTable); // add scrollpane
		trialRankScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		

		//instance of CardsCollection to access the methods in there
		cardsCollection = new CardsCollection();
		
		layout = new GridBagLayout();
		setLayout(layout);
		constraints = new GridBagConstraints();
		
		//a line to on each border
		Border blackline = BorderFactory.createLineBorder(Color.black);
		
		gameRankTable.setBorder(blackline);
		trialRankTable.setBorder(blackline);	
		
		/*
		 * Game Rank Panel will display the game rank in a JTable
		 */
		gameRankPanel = new JPanel(new BorderLayout());	
		gameRankPanel.setBorder(blackline);
		
		gameRankLabel = new JLabel("GAME RANK");
		gameRankLabel.setBorder(blackline);
		
		gameRankPanel.add(gameRankLabel, BorderLayout.NORTH);
		gameRankPanel.add(gameRankScrollPane, BorderLayout.CENTER);

		/*
		 *  Trial Rank Panel will display the trial rank in a JTable
		 */
		trialRankPanel = new JPanel(new BorderLayout());
		trialRankPanel.setBorder(blackline);
		
		trialRankLabel = new JLabel("TRIAL RANK");
		trialRankLabel.setBorder(blackline);
		
		trialRankPanel.add(trialRankLabel, BorderLayout.NORTH);
		trialRankPanel.add(trialRankScrollPane, BorderLayout.CENTER);
		
		

		/*
		 * Current Status Panel will show the status of the game
		 */
		currentStatusPanel = new JPanel(new FlowLayout());
		currentStatusPanel.setBorder(blackline);
		currentStatusLabel = new JLabel("Current Status: ");
		
		statusesLabel = new JLabel();
		currentStatusPanel.add(currentStatusLabel);
		currentStatusPanel.add(statusesLabel);


		/*
		 * Dealer Panel will show the dealer's card and cards total
		 */
		dealerPanel = new JPanel(new GridBagLayout());
		dealerPanel.setBorder(blackline);
		dealerInfoPanel = new JPanel(new BorderLayout());
		
		dealerCardPanel = new JPanel(new GridLayout(0,5));
		
		dealerCardPanel.setBorder(blackline);
		
		//when the panel is active or need focus, it will be dark green color
		//else when it is inactive or doesn't not require focus, it will be light gray
		dealerCardPanel.setBackground(Color.LIGHT_GRAY);
		
		dealerLabel = new JLabel("DEALER CARD:");
		dealerCardScore = new JLabel();


		//adding the labels and the card score label to dealerInfoPanel
		dealerInfoPanel.add(dealerLabel, BorderLayout.NORTH);
		dealerInfoPanel.add(dealerCardScore, BorderLayout.CENTER);


		//adding the dealerInfoPanel and dealerCardPanel to the dealerPanel
		addCompWeight(dealerPanel, dealerInfoPanel, constraints, GridBagConstraints.VERTICAL, 0, 0, 1, 1, 0.7,3.0);
		addCompWeight(dealerPanel, dealerCardPanel, constraints, GridBagConstraints.BOTH, 1, 0, 5, 1, 4.0,1.0);
		
		/*
		 * the client panel is made up of two panel
		 * one is deck1Panel which will display the client card at first
		 * if the client splits, the splitted will be moved to deck2Panel
		 */
		clientPanel = new JPanel(new GridBagLayout());
		
		/*
		 * deck1Panel will show the cards total and cards of the first hand
		 */
		deck1Panel = new JPanel (new GridBagLayout());
		deck1Panel.setBorder(blackline);
		
		deck1InfoPanel = new JPanel(new BorderLayout());
		
		deck1CardPanel = new JPanel(new GridLayout(0, 5));
		deck1CardPanel.setBorder(blackline);
		deck1CardPanel.setBackground(Color.LIGHT_GRAY);
		                         
		deck1Label = new JLabel("DECK 1:     ");

		
		deck1CardScore = new JLabel();
		
		//adding the labels and card score label to the deck1InfoPanel
		deck1InfoPanel.add(deck1Label, BorderLayout.NORTH);
		deck1InfoPanel.add(deck1CardScore, BorderLayout.CENTER);

		//adding deck1InfoPanel and deck1CardPanel to deck1Panel
		addCompWeight(deck1Panel, deck1InfoPanel, constraints, GridBagConstraints.VERTICAL, 0, 0, 1, 1, 1.1,3.0);
		addCompWeight(deck1Panel, deck1CardPanel, constraints, GridBagConstraints.BOTH, 1, 0, 5, 1, 3.0,1.0);
		
		
		/*
		 * deck2Panel will be shown once the player splitted the card
		 */
		deck2Panel = new JPanel(new GridBagLayout());
		deck2Panel.setBorder(blackline);
		deck2InfoPanel = new JPanel(new BorderLayout());
		
		deck2CardPanel = new JPanel(new GridLayout(0, 5));
		deck2CardPanel.setBorder(blackline);
		deck2CardPanel.setBackground(Color.LIGHT_GRAY);
		
		deck2Label = new JLabel("DECK 2:     ");

		
		deck2CardScore = new JLabel();
		
		//adding the labels and deck2CardScore label to the deck2InfoPanel
		deck2InfoPanel.add(deck2Label, BorderLayout.NORTH);
		deck2InfoPanel.add(deck2CardScore, BorderLayout.SOUTH);
		
		//adding deck2InfoPanel and deck2CardPanel into deck2Panel
		addCompWeight(deck2Panel, deck2InfoPanel, constraints, GridBagConstraints.VERTICAL, 0, 0, 1, 1,1.1,3.0);
		addCompWeight(deck2Panel, deck2CardPanel, constraints, GridBagConstraints.BOTH, 1, 0, 5, 1,3.0,1.0);
		
		//adding deck1Panel into clientPanel. by default, deck2Panel is not added
		addCompWeight(clientPanel, deck1Panel, constraints, GridBagConstraints.BOTH, 0,0,1,1,2.0,1.0);

		/*
		 * the butonPanel will show the hit, stand and split button
		 */
		buttonPanel = new JPanel(new FlowLayout());
		buttonPanel.setBorder(blackline);
		hitButton = new JButton("Hit");
		hitButton.setEnabled(false);
		standButton = new JButton("Stand");
		standButton.setEnabled(false);
		splitButton = new JButton("Split");
		splitButton.setEnabled(false);
		
		//setting the action listener for all the buttons
		hitButton.addActionListener(
				new ActionListener()
				{
					@Override
					public void actionPerformed(ActionEvent e) {
						client.changeWaitStatus(ACT_HIT);
						
					}
				}
		);
		
		standButton.addActionListener(
				new ActionListener()
				{
					@Override
					public void actionPerformed(ActionEvent e) {
						client.changeWaitStatus(ACT_STAND);
						
					}
				}
		);
		
		splitButton.addActionListener(
				new ActionListener()
				{
					@Override
					public void actionPerformed(ActionEvent e) {
						client.changeWaitStatus(ACT_SPLIT);
						
					}
				}
		);
		
		//adding the button in the buttonPanel
		buttonPanel.add(hitButton);
		buttonPanel.add(standButton);
		buttonPanel.add(splitButton);
		
		
		/*
		 * This is the part that will add each JPanel to the JFrame
		 */
		
		
		//set the preferredSize of each JPanel
		gameRankPanel.setPreferredSize(new Dimension(350, 130));
		gameRankPanel.setMinimumSize(new Dimension(350, 130));
		gameRankPanel.setMaximumSize(new Dimension(350, 130));

		trialRankPanel.setPreferredSize(new Dimension(350, 130));
		trialRankPanel.setMinimumSize(new Dimension(350, 130));
		trialRankPanel.setMaximumSize(new Dimension(350, 130));

		currentStatusPanel.setPreferredSize(new Dimension(700, 40));
		currentStatusPanel.setMinimumSize(new Dimension(700, 40));
		currentStatusPanel.setMaximumSize(new Dimension(700, 40));
		
		dealerPanel.setPreferredSize(new Dimension(700, 150));
		dealerPanel.setMinimumSize(new Dimension(700, 150));
		dealerPanel.setMaximumSize(new Dimension(700, 150));
		
		clientPanel.setPreferredSize(new Dimension(700, 150));
		clientPanel.setMinimumSize(new Dimension(700, 150));
		clientPanel.setMaximumSize(new Dimension(700, 300));
		
		buttonPanel.setPreferredSize(new Dimension(700,40));
		buttonPanel.setMinimumSize(new Dimension(700,40));
		buttonPanel.setMaximumSize(new Dimension(700,40));
		
		//fiinally, adding each JPanel into the JFrame. 
		//by default, the clientPanel and buttonPanel is not added
		//it will only be added when a new game starts but not in observer mode
		addCompWeight(this, gameRankPanel, constraints, GridBagConstraints.BOTH, 0, 0, 1, 1,3.0,0.0);
		addCompWeight(this, trialRankPanel, constraints, GridBagConstraints.BOTH, 1, 0, 1, 1,3.0,0.0);
		addCompFill(this, currentStatusPanel, constraints, GridBagConstraints.BOTH, 0, 1, 2, 1);
		addCompFill(this, dealerPanel, constraints, GridBagConstraints.HORIZONTAL, 0, 2, 2, 1);
		
		//an instance of the client
		client = new BJClient(this, userName);		
		client.start();
		
		//forbid client from resizing the JFrame
		setResizable(false);
		
	}
		
	//adding component to the layout based on constraints
	private void addComp(Container parentCom, Component childCom, GridBagConstraints g, int x, int y, int numOfCol, int numOfRow)
	{
		g.gridx = x;
		g.gridy = y;
		g.gridwidth = numOfCol;
		g.gridheight = numOfRow;
		parentCom.add(childCom, g);
	}
  
	//this method allows to specify the constraint's FILL
	private void addCompFill(Container parentCom, Component childCom, GridBagConstraints g, int gbcFill, int x, int y, int numOfCol, int numOfRow)
	{
		int original_fill = constraints.fill;
		g.fill = gbcFill; 
		this.addComp(parentCom, childCom, g, x, y, numOfCol, numOfRow);
	
		g.fill = original_fill;
	}

	//this method allows to specify the constraint's WEIGHT
	private void addCompWeight(Container parentCom, Component childCom, GridBagConstraints g, int gbcFill, int x, int y, int numOfCol, int numOfRow, double weightX, double weightY)
	{
		int original_fill = constraints.fill;
		g.fill = gbcFill; 
		double original_WeightX = constraints.weightx;
		double original_WeightY = constraints.weighty;
		g.weightx = weightX;
		g.weighty = weightY;
		this.addComp(parentCom, childCom, g, x, y, numOfCol, numOfRow);
	
		g.weightx = original_WeightX;
		g.weighty = original_WeightY;
		g.fill = original_fill;
	}

	/*		 
	* Method that will be called by BJClient to update the game rank after each game
	*/
	public  void updateGameRank(Vector<Vector<String>> newGameRank)
	{
		gameRankPanel.remove(gameRankScrollPane);
	 
		gameRankTable = new JTable(newGameRank, columnNames)
		{
			public boolean isCellEditable(int rowIndex, int colIndex) 
			{
		        return false;   //Disallow the editing of any cell
		    }
		};
		
		 gameRankScrollPane = new JScrollPane(gameRankTable); // add scrollpane
		 gameRankScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
			
		
		//adding the game rank table to the JPanel
		gameRankPanel.add(gameRankLabel, BorderLayout.NORTH);
		gameRankPanel.add(gameRankScrollPane, BorderLayout.CENTER);
	
		gameRankPanel.revalidate();
		gameRankPanel.repaint();
	}
	
	/*		 
	* Method that will be called by BJClient to update the trial rank after each try
	*/
	public void updateTrialRank(Vector<Vector<String>> newTrialRank)
	{
		trialRankPanel.remove(trialRankScrollPane);
		
		trialRankTable = new JTable(newTrialRank, columnNames)
		{
			public boolean isCellEditable(int rowIndex, int colIndex) 
			{
		        return false;   //Disallow the editing of any cell
		    }
		};
		
		
		 trialRankScrollPane = new JScrollPane(trialRankTable); // add scrollpane
		 trialRankScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
		
		trialRankPanel.add(trialRankLabel, BorderLayout.NORTH);
		trialRankPanel.add(trialRankScrollPane, BorderLayout.CENTER);
	
		trialRankPanel.revalidate();
		trialRankPanel.repaint();
	}

	
	/*
	 * Method that will be called by BJClient and specify the outcome of the try and the end of each try
	 */
	public void changeStatus(String winner, int winnerValue)
	{
		if(winner.equals(STATUS_DRAW))
			statusesLabel.setText(winner + " at " + winnerValue + "!");
		else
			statusesLabel.setText(winner + " wins with " + winnerValue + "!");
	} 
	
	/*
	 * Method that will be called by BJClient to display certain message on the status bar
	 */
	public void setStatus(String msg)
	{
		statusesLabel.setText(msg);
	}

	/*
	 * Method that will be called by BJClient to set the card's total of dealer
	 */
	public void setDealerScore(String score)
	{
		dealerCardScore.setText("Total: " + score);
		
	}
	
	/*
	 * Method that will be called by BJClient to set the card's total of client's deck1 score
	 */
	public void setDeck1Score(int score)
	{
		deck1CardScore.setText("Total: " + Integer.toString(score));
	}
	
	/*
	 * Method that will be called by BJClient to set the card's total of client's deck2 score
	 */
	public void setDeck2Score(int score)
	{
		deck2CardScore.setText("Total: " + Integer.toString(score));
	}
	
	/*
	 * Method that will be called by BJClient to set the client 1st card and 2nd card
	 * It will only be called one time for each try and it is called at the beginning of each try
	 */
	public void updateCards(String dealerCard, String clientCard1, String clientCard2)
	{
		dealerCardLabel[0] = cardsCollection.getCardDisplay(dealerCard);
		dealerCardLabel[1] = cardsCollection.getCardDisplay("00");

		dealerCardPanel.add(dealerCardLabel[0]);
		dealerCardPanel.add(dealerCardLabel[1]);
		
		clientCardLabel[clientDeckCounter][clientCardCounter] = cardsCollection.getCardDisplay(clientCard1);
		deck1CardPanel.add(clientCardLabel[clientDeckCounter][clientCardCounter]);
		clientCardCounter++;
		
		clientCardLabel[clientDeckCounter][clientCardCounter] = cardsCollection.getCardDisplay(clientCard2);
		deck1CardPanel.add(clientCardLabel[clientDeckCounter][clientCardCounter]);
		clientCardCounter++;
		
		dealerCardPanel.revalidate();
		dealerCardPanel.repaint();
		deck1CardPanel.revalidate();
		deck1CardPanel.repaint();
		
	}
	
	/*
	 * Method that will be called by BJClient to set the dealer 1st and 2nd card
	 * It will only be called one time for each try and it is called at the beginning of each try
	 * One of the dealer's card is face down and not showing to the client
	 */
	public void updateCards(String dealerCard)
	{
		dealerCardLabel[0] = cardsCollection.getCardDisplay(dealerCard);
		dealerCardLabel[1] = cardsCollection.getCardDisplay("00");

		dealerCardPanel.add(dealerCardLabel[0]);
		dealerCardPanel.add(dealerCardLabel[1]);
		
		dealerCardPanel.revalidate();
		dealerCardPanel.repaint();
	}
	
	/*
	 * update the client card to specific deck
	 */
	public void updateClientCards(String newCard)
	{
		clientCardLabel[clientDeckCounter][clientCardCounter] = cardsCollection.getCardDisplay(newCard);
		
		//if clientDeckCounter == 0, it means user doesn't split card or if he splits, he still playing on the 1st deck card
		if(clientDeckCounter == 0)
		{
			deck1CardPanel.add(clientCardLabel[clientDeckCounter][clientCardCounter]);
			clientCardCounter++;
			deck1CardPanel.revalidate();
			deck1CardPanel.repaint();
		}
		
		//if clientDeckCounter == 1, it means user does split card and he has done playing hte 1st deck card and would like
		//to play the 2nd deck card
		else if(clientDeckCounter == 1)
		{
			deck2CardPanel.add(clientCardLabel[clientDeckCounter][clientCardCounter]);
			clientCardCounter++;
			deck2CardPanel.revalidate();
			deck2CardPanel.repaint();
		}
		
	}
	
	/*
	 * Method that will update the dealer's card
	 * Since one of the dealer's card is not shown at the begining of the game
	 * it will be removed before displaying the remaining class
	 */
	public void updateDealerCard(String newCard)
	{
		if(dealerCardCounter == 1)
		{
			dealerCardPanel.remove(1);
		}
		
		dealerCardLabel[dealerCardCounter] = cardsCollection.getCardDisplay(newCard);
		dealerCardPanel.add(dealerCardLabel[dealerCardCounter]);
		dealerCardCounter++;
		
		dealerCardPanel.revalidate();
		dealerCardPanel.repaint();
	}
	
	/*
	 * This method will be called by BJClient when the user hit split.
	 * This will show the deck2Panel and the appropriate card is moved to 2nd deck
	 */
	public void splitCard(String deck2Card)
	{
		deck1CardPanel.remove(1);
		clientCardCounter--;
		
		//adding deck2Panel into the clientPanel
		addCompWeight(clientPanel, deck2Panel, constraints, GridBagConstraints.BOTH, 0,1,1,1,2.0,1.0);
		clientPanel.revalidate();
		clientPanel.repaint();
		
		clientCardLabel[1][0] = cardsCollection.getCardDisplay(deck2Card);
		deck2CardPanel.add(clientCardLabel[1][0]);
		
		//Makes Frame Longer
		
		Dimension d = getSize();
		d.setSize(d.getWidth(), d.getHeight() + 150);
		setSize(d);
		
		clientPanel.setPreferredSize(new Dimension(700, 300));
		clientPanel.setMinimumSize(new Dimension(700, 300));
		clientPanel.setMaximumSize(new Dimension(700, 300));
	
		clientPanel.revalidate();
		clientPanel.repaint();
	}
	
	/*
	 * increase the counter so that the array now is in 2nd deck
	 * then the user can hit or stand for the 2nd deck's card
	 */
	public void setDeck2()
	{
		clientCardCounter = 0;
		clientDeckCounter = 1;
	}

	/*
	 * By default all the buttons are disabled
	 * It will only be enabled when the server thinks the move is possible
	 */
	public void enableButton(String buttonName, boolean status)
	{
		if(buttonName == "HitButton")
		{
			hitButton.setEnabled(true);
		}
		else if(buttonName == "StandButton")
		{
			standButton.setEnabled(true);
		}
		else if(buttonName == "SplitButton")
		{
			splitButton.setEnabled(true);
		}
	}

	/*
	 * disable all the button
	 */
	public void disableButton()
	{
		hitButton.setEnabled(false);
		standButton.setEnabled(false);
		splitButton.setEnabled(false);
	}
	
	/*
	 * this is the reset all the GUI layout after one try
	 * all the cards dispalyed will be removed and the GUI size will be resize to the default size.
	 */
	public void resetGame()
	{
		dealerCardPanel.removeAll();
		dealerCardPanel.revalidate();
		dealerCardPanel.repaint();
		deck1CardPanel.removeAll();
		deck1CardPanel.revalidate();
		deck1CardPanel.repaint();

		if(client.isSplitted() == true)
		{
			deck2CardPanel.removeAll();
			deck2CardPanel.validate();
			deck2CardPanel.repaint();
			clientPanel.remove(1);
			clientPanel.revalidate();
			clientPanel.repaint();
			setDeck2Score(2);
			
			//resize the JFrame to the size before being splitted
			Dimension d = getSize();
			d.setSize(d.getWidth(), d.getHeight() - 150);
			setSize(d);
			
			clientPanel.setPreferredSize(new Dimension(700, 150));
			clientPanel.setMinimumSize(new Dimension(700, 150));
			clientPanel.setMaximumSize(new Dimension(700, 150));
		}

		
		
		clientCardCounter = 0;
		dealerCardCounter = 1;
		clientDeckCounter = 0;
		
		disableButton();
		
		deck1CardPanel.setBackground(Color.LIGHT_GRAY);
		deck2CardPanel.setBackground(Color.LIGHT_GRAY);
		dealerCardPanel.setBackground(Color.LIGHT_GRAY);
	}
	
	/*
	 * According to the requirement, after 5 tries, the score will be transfered into the game rank panel
	 * Thus the trial rank has to be reset
	 * This method will reset the trial rank
	 */
	public void resetTrialRank()
	{
		Vector<Vector<String>> newTrialRank = new Vector<Vector<String>>();
		newTrialRank.addElement(new Vector<String>());
		
				
		trialRankPanel.remove(trialRankScrollPane);
		
		trialRankTable = new JTable(newTrialRank, columnNames)
		{
			public boolean isCellEditable(int rowIndex, int colIndex) 
			{
		        return false;   //Disallow the editing of any cell
		    }
		};
		
		
		trialRankScrollPane = new JScrollPane(trialRankTable); // add scrollpane
		trialRankTable.setFillsViewportHeight(true);
		
		trialRankPanel.add(trialRankLabel, BorderLayout.NORTH);
		trialRankPanel.add(trialRankScrollPane, BorderLayout.CENTER);
	
			
		trialRankPanel.revalidate();
		trialRankPanel.repaint();
				
				
	}
	
	/*
	 * will set the deck1 color to green if it needs attention
	 */
	public void deck1Turn()
	{
		deck1CardPanel.setOpaque(true);
		deck1CardPanel.setBackground(Color.GREEN.darker());
	}
	
	/*
	 * will set the deck2 color to green if it needs attention
	 * set deck1 color to grey since it doesn't require attention anymore
	 */
	public void deck2Turn()
	{
		deck2CardPanel.setOpaque(true);
		deck1CardPanel.setBackground(Color.LIGHT_GRAY);
		deck2CardPanel.setBackground(Color.GREEN.darker());
	}
	
	/*
	 * will set the dealer deck color to green if it needs attention
	 * set deck1 and deck2 color to grey since it doesn't require attention anymore
	 */
	public void dealerTurn()
	{
		dealerCardPanel.setOpaque(true);
		dealerCardPanel.setBackground(Color.GREEN.darker());
		deck1CardPanel.setBackground(Color.LIGHT_GRAY);
		if(client.isSplitted())
		{
			deck2CardPanel.setBackground(Color.LIGHT_GRAY);
		}
	}
	
	//by default, the GUI won't display the client and button panel in observer mode
	//it will only be displayed once the client starts playing the game and the cards are issued to him
	public void addClientButtonPanel()
	{
		setSize(700,535);
		addCompFill(this, clientPanel, constraints, GridBagConstraints.HORIZONTAL, 0, 3, 2, 1);
		addCompFill(this, buttonPanel, constraints, GridBagConstraints.HORIZONTAL, 0, 4, 2, 1);
	}
			
	//main method
	public static void main(String[] args) throws IOException
	{
		GUI test = new GUI();
		test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		test.setSize(700,335);
		test.setLocationRelativeTo(null);
		test.setVisible(true);
	}

}

